package com.weiwei.diancan.base;

import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.weiwei.diancan.R;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;

/**
 * Created by BMW on 2016/11/4.
 */
public abstract class  BaseActivity extends AppCompatActivity {


    protected TextView titler;
    protected TextView iv_left;
    protected TextView iv_right;
    protected ImageView iv;
    public ProgressDialog progressDialog;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setLayoutView();
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE |
                WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
        progressDialog = new ProgressDialog(this);
        progressDialog.setCancelable(false);


        titler = (TextView) findViewById(R.id.titler);
        iv_left = (TextView) findViewById(R.id.iv_left);
        iv_right = (TextView) findViewById(R.id.iv_right);
        iv = (ImageView)findViewById(R.id.iv);
        initTitle();
        initView();
        setListeners();
        getData();
    }


    public abstract void getData();

    public abstract void setListeners();

    public abstract void initView();

    public abstract void initTitle();

    public abstract void setLayoutView();

    public void openActivity(Class<?> c,Bundle v){
        Intent intent = new Intent(this,c);
        if(v!=null){
            intent.putExtras(v);
        }
        startActivity(intent);
    }

    /**
     * 关闭软键盘
     */
    public void closeInput(EditText edit){
        InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(edit.getWindowToken(),0);
    }
}
